import pymysql

class Sql(object):
    def output_sql(self,data):
        conn = pymysql.Connect(
            host = "127.0.0.1",
            port = 3306,
            user = 'root',
            passwd = '123456',
            db = 'data_collection',
            charset = 'utf8'
        )
        cursor = conn.cursor()
        sql_insert = "insert into data_51job_she" \
                     "(Job_Title, Job_Type ,Job_Place , Add_Time , Recruit_Way , Job_Duties , Job_Requirement , " \
                     "Job_Pay , Company_Name , Num_People , Work_Experience , Academic ,  Job_Boon , Company_Type) " \
                     "value('%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" \
                     % (data['Job_Title'] , data['Job_Type'] , data['Job_Place'] , data['Add_Time'] , data['Recruit_Way'] , data['Job_Duties'] , data['Job_Requirement'] ,
                        data['Job_Pay'] , data['Company_Name'] , data['Num_People'] , data['Work_Experience'] , data['Academic'] , data['Job_Boon'] , data['Company_Type'])
        try:
            cursor.execute(sql_insert)
            conn.commit()
            print(cursor.rowcount)

        except Exception as e:
            print(e)
            #回滚
            conn.rollback()
        cursor.close()
        conn.close()

